home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / doCreateSubcharacterArgList. < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.5 KB  |  218 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Feb, 2000
  22. //  Author:         bb
  23. //
  24. //    Procedure Name:
  25. //        doCreateSubcharacterArgList
  26. //
  27. //    Description:
  28. //        Create a new sub character
  29. //
  30. //    Input Arguments:
  31. //    $version: The version of this option box.  Used to know how to 
  32. //    interpret the $args array.
  33. //        "1" : $name
  34. //  
  35. //    $args
  36. //    Version 1
  37. //    [0]        $name :  name to give the new character
  38. //  [1]     $excludeTranslate : exclude translate attrs when creating char
  39. //  [2]     $excludeRotate : exclude rotate attrs when creating char
  40. //  [3]     $excludeScale : exclude scale attrs when creating char
  41. //  [4]     $excludeVis : exclude visibility attrs when creating char
  42. //  [5]     $excludeDynamic : exclude dynamic attrs when creating char
  43. //  [6]     $channelBox : create based on channel box selections
  44. //
  45. //    Return Value:
  46. //        New subcharacter name
  47. //
  48.  
  49. global proc string doCreateSubcharacterArgList( string $version,
  50.                                                 string $args[] )
  51. {
  52.     string $name = $args[0];
  53.     int $excludeTranslate = $args[1];
  54.     int $excludeRotate = $args[2];
  55.     int $excludeScale = $args[3];
  56.     int $excludeVisibility = $args[4];
  57.     int $excludeDynamic = $args[5];
  58.     int $useChannelBox = $args[6];
  59.  
  60.     // See if there is a current character
  61.     //
  62.     string $currChar[] = `currentCharacters`;
  63.     if (size($currChar) == 0) {
  64.         error "Must have a current character.";
  65.         return "";
  66.     }
  67.     if (size($currChar) > 1) {
  68.         error "Must have a single current character.";
  69.         return "";
  70.     }
  71.     
  72.     string $currentSelection[] = `ls -selection`;
  73.     string $currentSelectionTypes[] = `ls -selection -st`;    
  74.     string $attrs[];
  75.     string $attrsInCharacter[];
  76.     if ($useChannelBox) {
  77.         $attrs = `selectedChannelBoxPlugs`;
  78.         if (size($attrs) == 0) {
  79.             error("No attributes were selected in the channel box.");
  80.             return "";
  81.         }
  82.     } else {
  83.         int $excludeTransform = $excludeTranslate + $excludeRotate + $excludeVisibility + $excludeScale;
  84.         int $selCount = size($currentSelection);
  85.         int $ii;
  86.         for ($ii = 0; $ii < $selCount; $ii++) {
  87.             string $sel = $currentSelection[$ii];
  88.             string $selType = $currentSelectionTypes[$ii*2+1];
  89.             
  90.             if ($sel == $currChar[0]) {
  91.                 warning("Skipping '"+$sel+"'. Cannot make a character a subcharacter of itself.");
  92.                 continue;
  93.             }
  94.  
  95.             string $selName = $sel;
  96.             if ($selType != "float3" && $selType != "double3") {
  97.                 if (nodeType($sel) != $selType) {
  98.                     warning("Skipping '"+$sel+"'. Unless you use the channel box option, only selected nodes can be made into subcharacters.");
  99.                     continue;
  100.                 }
  101.             } else {
  102.                 // For point-type attributes (cv's and vertices), the
  103.                 // attribute name differs from the component name. Strip off
  104.                 // the component name.
  105.                 //
  106.                 string $buffer[];
  107.                 int $result = tokenize($sel,".",$buffer);
  108.                 $selName = $buffer[0];
  109.  
  110.                 // components may also be tweaks ... take that into
  111.                 // account as well
  112.                 //
  113.                 string $isControlPoint[];
  114.                 $isControlPoint = `ls -type controlPoint $selName`;
  115.                 if (!size($isControlPoint)) {
  116.                     $isControlPoint = `listRelatives -ni -s -typ controlPoint $selName`;
  117.                 }
  118.                 if (size($isControlPoint)) {
  119.                     string $tmp[];
  120.                     $tmp = `listConnections ($isControlPoint[0]+".tweakLocation")`;
  121.                     if (size($tmp)) {
  122.                         $selName = $tmp[0];
  123.                     }
  124.                 }
  125.             }
  126.             
  127.             if (nodeType($sel) == "character") {
  128.                 warning("Skipping '"+$sel+"'. Select nodes or attributes that you want to put into the subcharacter. Do not select characters.");
  129.                 continue;
  130.             }
  131.             
  132.             string $keyableAttrs[] = `listAttr -m -k $sel`;
  133.             for ($at in $keyableAttrs) {
  134.  
  135.                 // build a list of the attributes in the character
  136.                 //
  137.                 if ($excludeDynamic) {
  138.                     string $userDefined[] = `listAttr -ud ($selName+"."+$at)`;
  139.                     if (size($userDefined) > 0) {
  140.                         continue;
  141.                     }
  142.                 }
  143.  
  144.                 if ($excludeTransform == 0) {
  145.                     $attrs[size($attrs)] = ($selName+"."+$at);
  146.                     continue;
  147.                 }
  148.                 
  149.                 string $isTransform[] = `ls -type transform $selName`;
  150.                 if (size($isTransform) == 0) {
  151.                     $attrs[size($attrs)] = ($selName+"."+$at);                    
  152.                     continue;
  153.                 }
  154.                 
  155.                 if ($excludeVisibility && $at == "visibility") {
  156.                     continue;
  157.                 } 
  158.                 if ($excludeScale &&
  159.                     ($at == "scaleX" || $at == "scaleY" || $at == "scaleZ"))
  160.                     continue;
  161.                 if ($excludeTranslate &&
  162.                     ($at == "translateX" || $at == "translateY" ||
  163.                      $at == "translateZ")) {
  164.                     continue;
  165.                 }
  166.                 if ($excludeRotate &&
  167.                     ($at == "rotateX" || $at == "rotateZ" || $at == "rotateY")) {
  168.                     continue;
  169.                 }
  170.  
  171.                 $attrs[size($attrs)] = ($selName+"."+$at);
  172.             }
  173.         }
  174.         if (size($currentSelection) > 0 && (size($attrs) == 0)) {
  175.             error("No valid subcharacter objects were selected.");
  176.             return "";
  177.         }
  178.     }
  179.  
  180.     int $cc;
  181.     for ($cc = 0; $cc < size($attrs); $cc++) {
  182.         if (nodeType($attrs[$cc]) == "character") {
  183.             string $dstConn[] = `listConnections -s 0 -d 1 -p 1 $attrs[$cc]`;
  184.             for ($dst in $dstConn) {
  185.                 string $dp;
  186.                 catch($dp = `character -q -cp $dst`);
  187.                 if ($dp == $attrs[$cc]) {
  188.                     $attrs[$cc] = $dst;
  189.                 }
  190.             }
  191.         }
  192.         if (`character -isMember $currChar[0] $attrs[$cc]`) {
  193.             $attrsInCharacter[size($attrsInCharacter)] = $attrs[$cc];
  194.         }
  195.     }
  196.  
  197.     // Build the create character command
  198.     //
  199.     $cmd = ( "character -empty -name \"" + $name + "\";");
  200.  
  201.     // Create the new character
  202.     //
  203.     string $character = eval( $cmd );
  204.     
  205.     $cmd = ( "character -edit -add "+$currChar[0]+" "+$character );
  206.     eval($cmd);
  207.  
  208.     if (size($attrs)) {
  209.         $cmd = ("character -edit -forceElement "+$character);
  210.         for ($at in $attrs) {
  211.             $cmd += (" "+$at);
  212.         }
  213.         eval($cmd);
  214.     }
  215.  
  216.     return $character;
  217. }
  218.